<script setup>
import { introApi } from "@/services/index";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { nextTick, ref, watch, onMounted } from "vue";
import { appInfo, loginSwitch } from "@/services/user";

onLoad((e) => {
  code.value = e.code;
  getList();
});

const code = ref("");
const introData = ref([]);

const getList = async () => {
  try {
    // 发送请求
    let res = await appInfo({});
    if (res.code == 200) {
      introData.value = res.data.employees;
      if (res.data.employees.length <= 1) {
        uni.redirectTo({
          url: "/pages/cashier/sales_order/index",
        });
      }
      // if (res.data.employees <= 0) {
      //   uni.redirectTo({
      //     url: "/pages/cashier/sales_order/index",
      //   });
      // }

      //     uni.navigateTo({
      //   url: `/pages/cashier/sales_order/index?ids=${
      //     item.shopId
      //   }&shopName=${decodeURIComponent(item.shopName)}`,
      // });
    }
  } catch (e) {
    uni.showToast({
      title: e.info,
      icon: "none",
    });
  }
};
const selectFun = async (item) => {
  uni.navigateTo({
    url: `/pages/cashier/sales_order/index?ids=${
      item.shopId
    }&shopName=${decodeURIComponent(item.shopName)}`,
  });
};

const goadd = () => {
  uni.navigateTo({
    url: "/pages/cashier/sales_order/index",
  });
};
const onClickLeft = () => history.back();
const onClickRight = () => showToast("按钮");

const themeVars = ref({
  navBarIconColor: "#000000",
  navBarTextColor: "#000000",
  navBarBackground: "transparent",
});

//无网状态
const connected = () => {
  getList();
};
</script>

<template>
  <top-nav :title="'选择门店'" :border="false" rType="save"></top-nav>
  <!-- <van-config-provider :theme-vars="themeVars">
    <van-nav-bar
      title=" "
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
      :safe-area-inset-top="true"
      :fixed="true"
      z-index="10"
      :placeholder="true"
    />
  </van-config-provider> -->
  <view class="content">
    <view class="content-title">请选择</view>
    <view class="content-des">可单选或查询全部订单 </view>
  </view>
  <view class="content-list">
    <!-- <view class="content-list-item" @click="selectFun(item)">
      <view class="content-list-left">
        <view class="content-list-item-shop">{{ "查询全部" }}</view>
      </view>
      <view class="content-list-right">
        <van-icon name="arrow" size="28rpx" color="#000000" />
      </view>
    </view> -->
    <view
      class="content-list-item"
      v-for="(item, index) in introData"
      :key="index"
      @click="selectFun(item)"
    >
      <view class="content-list-left">
        <view class="content-list-item-shop">{{ item.shopName }}</view>
        <view class="content-list-item-employeeNo"
          >{{ item.name }} {{ item.employeeNo }}</view
        >
      </view>
      <view class="content-list-right">
        <van-icon name="arrow" size="28rpx" color="#000000" />
      </view>
    </view>
  </view>

  <view class="goods_bt">
    <view class="goods_bt_to"
      ><up-button
        @click="goadd"
        type="primary"
        color="#1679FB"
        text="查询全部销售订单"
      ></up-button>
    </view>
  </view>
  <noWork @connected="connected"> </noWork>
</template>

<style lang="scss" scoped>
@import "index.scss";
</style>
